package com.base;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.util.ArrayList;

import javax.naming.InitialContext;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.mysqld.Mysqld;
import com.tools.Tools;

public class ChangOwnPssword extends JPanel{

	
		int WIDTH;
		int HEIGH;
		String account;
		String pow;
	public  ChangOwnPssword (int width,int heigh,String account,String pow){
		this.WIDTH=width;
		this.HEIGH=heigh;
		this.account=account;
		this.pow=pow;
		
		init();
	}
	void init() {
		this.setPreferredSize(new Dimension(WIDTH,HEIGH));
		
		JLabel jLabel=new JLabel("新密码");
		JTextField jTextField =new JTextField(12);
		JButton jButton =new JButton ("修改密码");
		this.add(jLabel);
		this.add(jTextField);
		this.add(jButton);
		
		jButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				
				
				
				if(jTextField.getText().equals("")) {
					Tools.messageWindows("请输入密码");
				}else {
					
					int n = 0;
					if(pow.equals("1")) {
						//如果为1则是管理员
						String string="update users_man set password=? where account=?";
						String data[]= {jTextField.getText(),account};
						n=Mysqld.upDate(string, data);
						//成功返回1
						
					}
					if(pow.equals("2")) {
						//如果为1则是管理员
						String string="update teacher set password=? where account=?";
						String data[]= {jTextField.getText(),account};
						n=Mysqld.upDate(string, data);
					}
					if(pow.equals("3")) {
						//如果为1则是管理员
						String string="update student set password=? where account=?";
						String data[]= {jTextField.getText(),account};
						n=Mysqld.upDate(string, data);
					}
					if(n==1) {
						//更改成功
						Tools.messageWindows("密码更改成功");
						
					}
					if(n==0||n==-1) {
						//更改成功
						Tools.messageWindows("密码更改失败");
						
					}
					
				}
				
			
			}
		});
		
		
	}
}
